/****************************************************************************/
/* File: scs-action.cpp                                                     */
/* Desc: Implementation file for the input action type                      */
/* Created: 2014-11-12                                                      */
/* Revised: 2014-11-17                                                      */
/* Authors: Sterling P. de Mille                                            */
/****************************************************************************/

// specification file
#include "scs-action.h"

SCSaction::SCSaction ()
{
	Init("Action", CONTINUOUS_ACTION);
}

void SCSaction::Init (SCSstring sLabel, const SCSint iButtonBehavior)
{
	m_sLabel = sLabel;
	m_iButtonBehavior = iButtonBehavior;
	Reset();
}

SCSstring SCSaction::GetLabel () const
{
	return m_sLabel;
}

void SCSaction::SetLabel (const SCSstring sLabel)
{
	m_sLabel = sLabel;
}

SCSint SCSaction::GetButtonBehavior () const
{
	return m_iButtonBehavior;
}

void SCSaction::SetButtonBehavior (const SCSint iButtonBehavior)
{
	m_iButtonBehavior = iButtonBehavior;
}

void SCSaction::Reset ()
{
	m_iState = INACTIVE;
	m_iOutputValue = 0;
	m_iInputValue = 0;
	m_iEnabled = SCS_FALSE;
}

void SCSaction::Tap ()
{
	Activate();
	Deactivate();
}

void SCSaction::Activate ()
{
	Activate(1);
}

void SCSaction::Activate (const SCSint iValue)
{
	SCSint iNext = SELECTED;
	switch (m_iState) {
	case SELECTED:
	case ACTIVE:
		iNext = ACTIVE;
		break;
	default:
		break;
	}
	m_iInputValue += iValue;
	m_iState = iNext;
}

void SCSaction::Deactivate ()
{
	SCSint iNext = DESELECTED;
	switch (m_iState) {
	case DESELECTED:
	case INACTIVE:
		iNext = INACTIVE;
		break;
	default:
		break;
	}
	m_iState = iNext;
}

void SCSaction::Update ()
{
	m_iOutputValue = ProcessOutputValue();
	m_iEnabled = (m_iOutputValue != 0);
}

SCSbool SCSaction::Enabled () const
{
	return m_iEnabled;
}

SCSint SCSaction::ProcessOutputValue ()
{
	SCSint iValue = m_iInputValue;
	if (iValue != 0) {
		if ((m_iState == DESELECTED) || (m_iState == INACTIVE)) {
			m_iInputValue = 0;
		}
		if (m_iButtonBehavior == SINGLE_ACTION) {
			m_iInputValue = 0;
		}
	}
	return iValue;
}

SCSint SCSaction::Value () const
{
	return m_iOutputValue;
}
